import { $post } from '@js/authRequest'
import { confirmAction } from '@js/tool'

export async function createApproveRequest (flowName, caseid, callback = () => {}, forcepassage) {
  const data = { flow_name: flowName, caseid }
  if (forcepassage) {
    data.forcepassage = 1
  }
  const res = await $post('/api/vendor/flowinstance', data)
  if (res.status === 0) {
    throw new Error(res.message)
  } else if (res.status === 2) {
    confirmAction(res.message, () => createApproveRequest(flowName, caseid, callback, true))
  } else {
    callback()
  }
}
